var utils = require("../../../utils/util.js");
var app = getApp();
var order = ['demo1', 'demo2', 'demo3']
Page({
  data: {
    imgUrls: [],
    indicatorDots: false,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    toView: 'green',
    categoryArr:[],
    firstArr:[],
    secondArr:[],
    dominameImg: utils.dominameImg
  },
  scroll: function (e) {
    console.log(e)
  },
  tap: function (e) {
    for (var i = 0; i < order.length; ++i) {
      if (order[i] === this.data.toView) {
        this.setData({
          toView: order[i + 1],
          scrollTop: (i + 1) * 200
        })
        break
      }
    }
  },
  tapMove: function (e) {
    this.setData({
      scrollTop: this.data.scrollTop + 10
    })
  },
  goProductDetail:function(e){
    wx.navigateTo({
      url: '../shopMallProductDetail/productDetail',
    })
  },
  goClassific: function (e) {
    wx.navigateTo({
      url: '../shopMallClassific/Classific?id=' + e.currentTarget.id,
    })
  },
  shunt:function(e){
    switch (e.currentTarget.dataset.info.pic_value_type){
      case (1):
        wx.navigateTo({
          url: '../iframe/iframe?url=' + encodeURI(e.currentTarget.dataset.info.pic_value_parameter),
        });
        break;
      case (2):
        wx.navigateTo({
          url: '../shopMallProductDetail/productDetail?id=' + encodeURI(e.currentTarget.dataset.info.pic_value_parameter),
        });
        break;
      case (4):
        wx.navigateTo({
          url: '../shopMallClassific/Classific?id=' + encodeURI(e.currentTarget.dataset.info.pic_value_parameter),
        });
        break;
    }
  },
  onLoad: function (options) {
    var that = this;
    //分类
    wx.showLoading({
      title: "数据加载中",
      mask: true
    });
    wx.request({
      url: utils.dominame + '/api/v1/goods/firstCategory',
      data: {},
      method: 'GET',
      header: { "Content-Type": "application/x-www-form-urlencoded" },
      success: function (res) {
        console.log(res);
        if (res.data.code == 0) {
          that.setData({
            categoryArr: res.data.data.rows
          });
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
      },
      fail: function (res) {
        wx.showToast({
          title: '网络异常',
          icon: 'none',
          duration: 2000
        })
      }
    })
    //banner
    wx.request({
      url: utils.dominame + '/api/v1/basic/getAdvertList2',
      data: { advert_site:1},
      method: 'GET',
      header: { "Content-Type": "application/x-www-form-urlencoded" },
      success: function (res) {
        console.log(res);
        if (res.data.code == 0) {
          that.setData({
            imgUrls: res.data.data[0].picInfo
          });
          console.log(that.data.imgUrls);
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
      },
      fail: function (res) {
        wx.showToast({
          title: '网络异常',
          icon: 'none',
          duration: 2000
        })
      }
    })
    //第一组
    wx.request({
      url: utils.dominame + '/api/v1/basic/getAdvertList2',
      data: { advert_site: 2 },
      method: 'GET',
      header: { "Content-Type": "application/x-www-form-urlencoded" },
      success: function (res) {
        console.log(res);
        if (res.data.code == 0) {
          that.setData({
            firstArr: res.data.data[0].picInfo
          });
          console.log(that.data.firstArr)
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
      },
      fail: function (res) {
        wx.showToast({
          title: '网络异常',
          icon: 'none',
          duration: 2000
        })
      }
    });
    //第二组
    wx.request({
      url: utils.dominame + '/api/v1/basic/getAdvertList2',
      data: { advert_site: 3 },
      method: 'GET',
      header: { "Content-Type": "application/x-www-form-urlencoded" },
      success: function (res) {
        console.log(res);
        if (res.data.code == 0) {
          that.setData({
            secondArr: res.data.data[0].picInfo
          });
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
      },
      fail: function (res) {
        wx.showToast({
          title: '网络异常',
          icon: 'none',
          duration: 2000
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    setTimeout(() => {
      wx.hideLoading();
    }, 100);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})